class ColumnasController < ApplicationController
  # GET /columnas
  # GET /columnas.xml
  def index
    @columnas = Columna.paginate :page => params[:page]


    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @columnas }
    end
  end

  # GET /columnas/1
  # GET /columnas/1.xml
  def show
    @columna = Columna.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @columna }
    end
  end

  # GET /columnas/new
  # GET /columnas/new.xml
  def new
    @columna = Columna.new(params[:columna])
    @columnas = @columna.modelo.try(:db_columnas)

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @columna }
    end
  end

  # GET /columnas/1/edit
  def edit
    @columna = Columna.find(params[:id])
    @columnas = @columna.modelo.try(:db_columnas)
  end

  # POST /columnas
  # POST /columnas.xml
  def create
    @columna = Columna.new(params[:columna])

    respond_to do |format|
      if @columna.save
        flash[:notice] =  'Columna creada correctamente.'
        format.html { params[:oper].nil? ? redirect_to(@columna) : render(:text => "Ok")}
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @columna.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /columnas/1
  # PUT /columnas/1.xml
  def update
    @columna = Columna.find(params[:id])

    respond_to do |format|
      if @columna.update_attributes(params[:columna])
        flash[:notice] = 'Columna actualizado correctamente.'
        format.html { redirect_to(@columna) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @columna.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /columnas/1
  # DELETE /columnas/1.xml
  def destroy
    @columna = Columna.find(params[:id])
    modelo_id=@columna.modelo_id
    @columna.destroy

    respond_to do |format|
      format.html { redirect_to(modelo_path(modelo_id)) }
      format.xml  { head :ok }
    end
  end

end
